﻿using System;

/*
 * 创建人：
 * 
 * 时间：
 * 
 * 说明：
 * 
 * 
 * 修改说明：
 * 
 * 
 */


namespace ConsoleTest.ChapterSix
{
    public class Security
    {
        /// <summary>
        /// 
        /// </summary>
        public static void DisplayStrongName()
        {
            System.Reflection.Assembly[] asses = System.AppDomain.CurrentDomain.GetAssemblies();
            foreach (System.Reflection.Assembly ass in asses)
            {
                DisplayFun(ass);
            }
        }
        /// <summary>
        /// 显示程序集的强名称
        /// </summary>
        private static void DisplayFun(System.Reflection.Assembly ass)
        {
            System.Reflection.AssemblyName name = ass.GetName();
            byte[] pubKey = name.GetPublicKey();
            //表示强名称的公钥信息类
            System.Security.Permissions.StrongNamePublicKeyBlob blob = new System.Security.Permissions.StrongNamePublicKeyBlob(pubKey);
            //提供代码程序集的强名称作为策略评估的证据
            System.Security.Policy.StrongName sn = new System.Security.Policy.StrongName(blob, name.Name, name.Version);
            System.Console.WriteLine("------------------------------------------------");
            System.Console.WriteLine(sn.Name);
            System.Console.WriteLine(sn.Version);
            System.Console.WriteLine(sn.PublicKey);
        }
    }
    
}